<template>
  <el-dialog title="委外订单详情" :close-on-click-modal="false" :visible.sync="visible" center fullscreen>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-row style="margin-bottom:15px;">
      <el-link style="margin-right:15px;" :href="printUrl" target="_blank" type="info">
        <el-button size="mini" type="info" @click="getPrintParams">打印单据</el-button>
      </el-link>
    </el-row>
    <el-form :model="dataForm" inline :rules="dataRule" ref="dataForm" label-width="120px">

      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="订单单号">
            <el-input v-model="dataForm.billId" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="销售单号">
            <el-input v-model="dataForm.saleBillId" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="订单类型">
            {{getSaleType(dataForm.consignType)}}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="审核人">
            <el-input v-model="dataForm.auditUserName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="制造商">
            <el-input v-model="dataForm.supplyName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="入库仓位">
            <el-input v-model="dataForm.inStockName" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="销售门店">
            <el-input v-model="dataForm.deptName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="顾客姓名">
            <el-input v-model="dataForm.customerName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="顾客卡号">
            <el-input v-model="dataForm.customerCard" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="审核时间">
            <el-input v-model="dataForm.auditTime" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="备注">
            <el-input v-model="dataForm.memo" readonly></el-input>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <table class="miui-table">
      <tr>
        <th>右眼(R)/左眼(L)</th>
        <th>球镜</th>
        <th>柱镜</th>
        <th>轴向</th>
        <th>基底</th>
        <th>曲率</th>
        <th>直径</th>
      </tr>
      <tr>
        <td>R</td>
        <td>{{optometry.ballGlassOd}}</td>
        <td>{{optometry.postGlassOd}}</td>
        <td>{{optometry.axesOd}}</td>
        <td>{{getBasalTypeData(optometry.basisOd)}}</td>
        <td>{{optometry.curvatureOd}}</td>
        <td>{{optometry.diameterOd}}</td>
      </tr>
      <tr>
        <td>L</td>
        <td>{{optometry.ballGlassOs}}</td>
        <td>{{optometry.postGlassOs}}</td>
        <td>{{optometry.axesOs}}</td>
        <td>{{getBasalTypeData(optometry.basisOs)}}</td>
        <td>{{optometry.curvatureOs}}</td>
        <td>{{optometry.diameterOs}}</td>
      </tr>
    </table>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40"></el-table-column>
      <el-table-column prop="billId" label="收货单号" width="140"></el-table-column>
      <el-table-column prop="goodsName" label="商品名称"></el-table-column>
      <el-table-column prop="goodsCode" label="商品代码" width="150"></el-table-column>
      <el-table-column prop="goodsSpec" label="商品规格" width="80"></el-table-column>
      <el-table-column prop="goodsQuantity" label="收货数量" width="80"></el-table-column>
      <el-table-column prop="batch" label="批次" width="100"></el-table-column>
      <el-table-column prop="invalidStr" label="失效日期" width="160"></el-table-column>
      <el-table-column prop="registerNum" label="注册证号" width="160"></el-table-column>

    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { saveNewCheckOrder, saveAndAuditOrder, getStockDataList, getCtgDataList } from '@/api/eims/check'
  import { allocationApplyAdd, allocationApplyGetObj, allocationApplyEdit } from '@/api/eims/allocation-apply'
  import { getConsignReceiptById, addConsignObj } from '@/api/eims/consign/consignReceipt.js'
  import { mapGetters } from 'vuex'
  import { remote } from '@/api/admin/dict'
  let params = '/consignInvisiblePrint.cpt&receiptId='
  export default {
    data() {
      return {
        visible: false,
        printUrl: '',
        dataForm: {
          id: 0,
          memo: '',
          detailList: []
        },
        deptOptions: [],
        saleTypeData: [],
        dataList: [],
        optometry: {},
        dataListLoading: false,
        dataRule: {

        },
        selectionList: [],
        receiveListVisible: false
      }
    },
    computed: {
      ...mapGetters(['permissions', 'bizData', 'userInfo'])
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        remote('sale_type').then(result => {
          this.saleTypeData = result.data.data
        })
        this.visible = true
        this.dataList = []
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getConsignReceiptById(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
                this.optometry = response.data.data.optometry
                let goodsData = response.data.data.detailList
                this.dataList = goodsData
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      consignMethodChange(val) {
        this.dataList = [...this.dataList]
      },
      //获取配镜类型枚举
      getSaleType(value) {
        let obj = {};
        obj = this.saleTypeData.find((item) => {
          return item.value == value;
        });
        if (obj && obj.label) {
          return obj.label;
        }
      },
      //获取基地类型枚举
      getBasalTypeData(value) {
        let obj = {};
        obj = this.bizData.basalTypeData.find((item) => {
          return item.value === value;
        });
        if (obj && obj.label) {
          return obj.label;
        }
      },
      // 打开商品列表弹窗
      openReceiveListDialog() {
        this.receiveListVisible = true
        this.$nextTick(() => {
          this.$refs.receiveList.init()
        })
      },
      handleSelectionChange(val) {
        this.selectionList = val
      },
      // 删除选中的商品
      delTableData() {
        this.selectionList.forEach((item, index) => {
          for (let i = 0; i < this.dataList.length; i++) {
            if (this.dataList[i] == item) {
              this.dataList.splice(i, 1)
            }
          }
          this.selectionList = []
        })
      },
      //更新表单数据
      updateFormData(obj) {
        let _this = this
        this.dataList = obj
        obj.forEach(item => {
          this.dataForm.detailList.push({
            goodsId: item.goodsId
          })
        })
      },
      //   获取品牌打印的参数
      getPrintParams() {
        let receiptId = this.dataForm.id
        this.printUrl = this.bizData.printUrl + params + receiptId
      }
    }
  }
</script>

<style lang="scss" scoped="scoped">
  .miui-table {
    width: 100%;
    margin: 10px 0;

    tr th,
    tr td {
      background-color: #b1e2ec3b;
    }

    tr th,
    tr td {
      padding: 10px 8px;
      border: solid 1px #f7f7f7;
      text-align: center;
    }
  }
</style>
